{include file="/sum/common/script" /}

<style>
    .withdraw-index .pay {
        width: 24px;
        height: 24px;
        margin-right: 8px;
    }

    .handle-popover .tip {
        margin-bottom: 16px;
    }

    .question-filled {
        color: var(--el-color-warning);
        margin-right: 4px;
    }
</style>

<div id="index" class="withdraw-index panel panel-default panel-intro" v-cloak>
    <el-container class="panel-block">
        <el-header class="sa-header">
            <el-tabs class="sa-tabs" v-model="state.filter.data.status" @tab-change="onChangeTab">
                <el-tab-pane v-for="item in type.data.status" :key="item" :label="item.name" :name="item.type">
                </el-tab-pane>
            </el-tabs>
            <div class="sa-title sa-flex sa-row-between">
                <div class="sa-title-left">
                    <div class="left-name">代理审核</div>
                    <sa-filter-condition v-model="state.filter" @filter-delete="onChangeFilter">
                    </sa-filter-condition>
                </div>
                <div class="sa-title-right">
                    <el-button class="sa-button-refresh" icon="RefreshRight" @click="getData"></el-button>
                    <el-button class="sa-button-refresh" icon="Search" @click="onOpenFilter"></el-button>

                    {if $auth->check('sum/agent/apply/add')}
                    <el-button icon="Plus" type="primary" @click="onAdd">代理申请</el-button>
                    {/if}

                </div>
            </div>
        </el-header>
        <el-main class="sa-main">
            <el-table height="100%" class="sa-table" :data="state.data" stripe @sort-change="onChangeSort">
                <el-table-column prop="id" label="ID" min-width="90" sortable="custom">
                </el-table-column>
                <el-table-column label="申请用户" min-width="158">
                    <template #default="scope">
                        <sa-user-profile :user="scope.row.user" :id="scope.row.user_id"></sa-user-profile>
                    </template>
                </el-table-column>
                <el-table-column label="用户姓名" min-width="132">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.user_name }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="联系电话" min-width="130">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.phone }}
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="代理区域" min-width="168" align="center">
                    <template #default="scope">
                        <div class="address-item sa-flex sa-flex-col sa-col-top">
                            <div class="name">
                                {{ scope.row.province_name }}/{{ scope.row.city_name }}/{{
                                scope.row.district_name
                                }}
                            </div>
                        </div>
                    </template>
                </el-table-column>

                <el-table-column prop="style" label="身份证人像照" min-width="120">
                    <template #default="scope">
                        <sa-image class="goods-image" :url="scope.row.image_sfzrx" size="64"></sa-image>
                    </template>
                </el-table-column>
                <el-table-column prop="style" label="身份证国徽照" min-width="120">
                    <template #default="scope">
                        <sa-image class="goods-image" :url="scope.row.image_sfzgh" size="64"></sa-image>
                    </template>
                </el-table-column>
                <el-table-column label="申请时间" width="172">
                    <template #default="scope">
                        {{ scope.row.createtime || '-' }}
                    </template>
                </el-table-column>
                <el-table-column label="上次操作时间" width="172">
                    <template #default="scope">
                        {{ scope.row.updatetime || '-' }}
                    </template>
                </el-table-column>
                <el-table-column label="状态" min-width="80">
                    <template #default="scope">
                        <div :class="`${state.statusStyle[scope.row.status]}`">
                            {{ scope.row.status_text }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" min-width="140">
                    <template #default="scope">
                        {if $auth->check('sum/agent/apply/handle')}
                        <template v-if="scope.row.status == 0">
                            <el-popover popper-class="handle-popover" v-model:visible="handlePopover.flag[scope.$index]"
                                :width="244" trigger="click">
                                <div class="tip sa-flex">
                                    <el-icon class="question-filled sa-color--warning">
                                        <question-filled />
                                    </el-icon>
                                    <div>您是否同意用户的代理申请？</div>
                                </div>
                                <div>
                                    <el-button @click="handlePopover.flag[scope.$index] = false" size="small">取消
                                    </el-button>
                                    <el-button type="primary" size="small" @click="onAgree(scope.row.id, scope.$index, 'agree')">同意
                                    </el-button>
                                </div>
                                <template #reference>
                                    <el-button type="primary" link>同意</el-button>
                                </template>
                            </el-popover>
                            <el-button type="danger" link @click="onRefuse(scope.row.id)">拒绝</el-button>
                        </template>
                        {/if}
                    </template>
                </el-table-column>
            </el-table>
        </el-main>
        <el-footer class="sa-footer sa-flex sa-row-right">
            <sa-pagination v-model="pagination" @pagination-change="getData"></sa-pagination>
        </el-footer>
    </el-container>
    <sa-filter v-model="state.filter" @filter-change="onChangeFilter"></sa-filter>
</div>